package com.xx;

import com.xx.dao.UserDao;
import com.xx.entity.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 许欣
 * 时间：2022/4/26 20:41
 * 描述：
 */
public class UserTest {

    @Test
    public void get() throws IOException {
        //查询
//        String resource="mybatis-config.xml";
//        //获取mybatis-config.xml的输入流
//        InputStream is= Resources.getResourceAsStream(resource);
//        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(is);
//        SqlSession sqlSession=sqlSessionFactory.openSession();
//        UserDao dao=  sqlSession.getMapper(UserDao.class);
//        //UserService dao=new UserServiceImpl();
//        User user=dao.getByAccount("admin");
//        System.out.println(user.getEmail());
//        //添加
//        User user=new User();
//        user.setAccount("lisi");
//        user.setPassword("123456");
//        user.setNick_name("王五");
//        user.setGender(2);
//        user.setId_card_no("182479657354862477");
//        user.setEmail("1234@56.com");
//        user.setPhone("18574085559");
//        user.setId(108);
//        String resource="mybatis-config.xml";
//        //获取mybatis-config.xml的输入流
//        InputStream is= Resources.getResourceAsStream(resource);
//        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(is);
//        SqlSession sqlSession=sqlSessionFactory.openSession();
//        UserDao dao=  sqlSession.getMapper(UserDao.class);
//        //UserService dao=new UserServiceImpl();
//        dao.update(user);
//        System.out.println(user.getEmail());

                String resource="mybatis-config.xml";
        //获取mybatis-config.xml的输入流
        InputStream is= Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession=sqlSessionFactory.openSession();
        UserDao dao=  sqlSession.getMapper(UserDao.class);
        //UserService dao=new UserServiceImpl();
        User user=dao.getById(31);
        System.out.println(user.getId());
    }
}
